Skip to content

Conversation

@BYK
Copy link
Member

@BYK BYK commented Nov 17, 2025

Before submitting a pull request, please take a look at our
Contributing guidelines and verify:

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

This PR addresses critical feedback regarding environment variable detection, particularly for Vite-based frameworks.

Key Changes:

  • packages/browser/src/utils/env.ts: The getEnvValue function now checks both process.env (for Webpack, Next.js, CRA) and import.meta.env (for Vite, Astro, SvelteKit). This ensures that environment variables (like those for Spotlight) are correctly detected across a wider range of bundlers and frameworks, fixing a significant compatibility issue.
  • packages/browser/test/utils/env.test.ts: Updated unit tests to focus on process.env scenarios. Added a note explaining that import.meta.env cannot be unit tested due to its read-only, compile-time nature and is covered by e2e tests.
  • packages/browser/src/utils/spotlightConfig.ts: Added a comment to clarify the explicit return undefined for readability, noting its optimization in production builds.

Open in Cursor Open in Web

Co-authored-by: burak.kaya <burak.kaya@sentry.io>
@BYK BYK marked this pull request as ready for review November 17, 2025 18:46
@BYK BYK merged commit 6ea8d90 into feat/spotlight-environment-variable-support Nov 17, 2025
46 checks passed
@BYK BYK deleted the cursor/process-and-resolve-pull-request-comments-1f87 branch November 17, 2025 18:46
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.63 kB added added
@sentry/browser - with treeshaking flags 23.13 kB added added
@sentry/browser (incl. Tracing) 41.28 kB added added
@sentry/browser (incl. Tracing, Profiling) 45.57 kB added added
@sentry/browser (incl. Tracing, Replay) 79.73 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.44 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 84.43 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 96.65 kB added added
@sentry/browser (incl. Feedback) 41.28 kB added added
@sentry/browser (incl. sendFeedback) 29.29 kB added added
@sentry/browser (incl. FeedbackAsync) 34.21 kB added added
@sentry/react 26.32 kB added added
@sentry/react (incl. Tracing) 43.22 kB added added
@sentry/vue 29.11 kB added added
@sentry/vue (incl. Tracing) 43.08 kB added added
@sentry/svelte 24.65 kB added added
CDN Bundle 27.01 kB added added
CDN Bundle (incl. Tracing) 41.9 kB added added
CDN Bundle (incl. Tracing, Replay) 78.45 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 83.91 kB added added
CDN Bundle - uncompressed 79.06 kB added added
CDN Bundle (incl. Tracing) - uncompressed 124.21 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 240.24 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 253 kB added added
@sentry/nextjs (client) 45.37 kB added added
@sentry/sveltekit (client) 41.67 kB added added
@sentry/node-core 50.92 kB added added
@sentry/node 158.13 kB added added
@sentry/node - without tracing 92.78 kB added added
@sentry/aws-serverless 106.55 kB added added

if (typeof import.meta !== 'undefined' && import.meta.env) {
// @ts-expect-error import.meta.env is typed differently in different environments
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const value = import.meta.env[key];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Vite: Dynamic Env Var Access Not Supported

The dynamic access import.meta.env[key] won't work in Vite-based frameworks. Vite performs static replacement at build time for literal property accesses like import.meta.env.VITE_VAR, but doesn't create a runtime object that supports bracket notation with variables. This means environment variables in Vite, Astro, and SvelteKit will never be retrieved despite the PR's intent to fix this compatibility issue.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants